package edu.scau.divineplace.controller;

import edu.scau.divineplace.config.global.log.WebLog;
import edu.scau.divineplace.entity.dos.ContentBasicInformationDO;
import edu.scau.divineplace.entity.dos.ContentExtraInformationDO;
import edu.scau.divineplace.entity.query.PageQuery;
import edu.scau.divineplace.entity.vo.content.ContentSimplyInfoVO;
import edu.scau.divineplace.entity.vo.commentscore.CommentScoreGroupVO;
import edu.scau.divineplace.entity.vo.content.ContentInfomationVO;
import edu.scau.divineplace.entity.vo.SearchResultVO;
import edu.scau.divineplace.entity.vo.content.RecentWorkVO;
import edu.scau.divineplace.service.ContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author: x1aolone
 * @Date: 2020/12/8 12:55
 */
@Slf4j
@RestController
@CrossOrigin
@Api("Content控制器")
@WebLog("Content控制器")
@Validated
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @ApiOperation("通过搜索词和搜索类型获取内容列表")
    @GetMapping("/search")
    public List<SearchResultVO> search(@NotNull String searchWord, Integer type, Long userId){
        return contentService.search(searchWord, type, userId);
    }

    @ApiOperation("通过内容id获取内容basic信息和extra信息")
    @GetMapping("/{contentId}")
    public ContentInfomationVO getInfo (@PathVariable Long contentId) {
        return contentService.getInfo(contentId);
    }

    @ApiOperation("通过内容id获取内容basic信息")
    @GetMapping("/basicInfo/{contentId}")
    public ContentBasicInformationDO getBasicInfo (@PathVariable Long contentId) {
        return contentService.getBasicInfo(contentId);
    }

    @ApiOperation("通过内容id获取内容extra信息")
    @GetMapping("/extraInfo/{contentId}")
    public List<ContentExtraInformationDO> getExtraInfo (@PathVariable Long contentId) {
        return contentService.getExtraInfo(contentId);
    }


    @ApiOperation("通过内容类型获取内容的排行榜，完美分页")
    @GetMapping("/rank/{contentType}")
    public List<ContentSimplyInfoVO> listRankContent (PageQuery pageQuery, @PathVariable Integer contentType) {
        return contentService.listRankContent(pageQuery, contentType);
    }

    @ApiOperation("通过内容类型获取最近更新的内容列表，完美分页")
    @GetMapping("/recent/{contentType}")
    public List<ContentSimplyInfoVO> listRecentContent (PageQuery pageQuery, @PathVariable Integer contentType) {
        return contentService.listRecentContent(pageQuery, contentType);
    }

    @ApiOperation("通过真人id获取参与的内容的信息，支持分页")
    @GetMapping("/recentWork/list/{roleId}")
    public List<RecentWorkVO> listRecentWork (PageQuery pageQuery, @PathVariable Long roleId, Long userId) {
        return contentService.listRecentWork(pageQuery, roleId, userId);
    }

}